package com.leet.code.lcof;

import java.util.LinkedHashMap;
import java.util.Map;

public class Code50 {

    public static void main(String[] args) {
        System.out.println(new Code50().firstUniqChar("abaccdeff"));

    }

    public char firstUniqChar(String s) {
        LinkedHashMap<Character, Integer> map = new LinkedHashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            Integer a = map.get(c);
            if (a == null) {
                map.put(c, 1);
            } else if (a == 1) {
                map.put(c, 2);
            }
        }


        for (Map.Entry<Character, Integer> entry : map.entrySet()) {
            if (entry.getValue() == 1) {
                return entry.getKey();
            }
        }

        return ' ';

    }

}
